<template>
  <div class="flexContent">
    <!-- 采购订单 -->
    <div class="searchBox">

      <el-form ref="form" :model="form" label-position="left" label-width="auto">
        <div class="serFlexBox">
          <div class="inputBox">
            <el-row :gutter="12" style="display: flex;flex-wrap: wrap;">
              <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
                <el-form-item label="门店名称" prop="storeId">
                  <el-select @click.native="getShopEasy" v-model="form.storeId" placeholder="请选择门店名称" style="width: 95%;"
                    filterable clearable popper-class="eloption">
                    <el-option v-for="item in shopLists" :key="item.id" :label="item.name" :value="item.id" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
                <el-form-item label="退货编号" prop="returnsNumber">
                  <el-input v-clearEmoji v-model.trim="form.returnsNumber" clearable placeholder="请输入退货编号"
                    style="width: 95%;" @keyup.enter.native="searchList" />
                </el-form-item>
              </el-col>
              <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
                <el-form-item label="状态" prop="returnsState">
                  <el-select v-model="form.returnsState" placeholder="请选择状态" clearable style="width: 95%;">
                    <el-option label="未审核" value="0" />
                    <el-option label="审核拒绝" value="1" />
                    <el-option label="审核通过" value="2" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <div class="btnBox">
            <el-button @click.stop="searchList" class="searchBtn" icon="el-icon-search">搜索</el-button>
            <el-button @click.stop="resetForm('form')" class="resetBtn" icon="el-icon-refresh-right">重置</el-button>
          </div>
        </div>
      </el-form>
    </div>
    <div class="table" id="tableBox" v-height>
      <div style="flex:1;">
        <vxe-table :column-config="{ resizable: true }" border class="tablebox" ref="xTable1"
          :row-config="{ isHover: true }" :scroll-y="{ enabled: true, gt: 21 }" style="width: 100%" height="100%"
          size="medium" align="center">
          <vxe-column type="seq" title="序号" width="80" />
          <vxe-column field="storeName" title="门店名称" :min-width="elTableAdaptationWidth('storeName', tableData)" />
          <vxe-column field="returnsNumber" title="退货编号"
            :min-width="elTableAdaptationWidth('returnsNumber', tableData)" />
          <vxe-column field="returnMoney" title="退货总额（元）" min-width="150" />
          <vxe-column field="updateTime" title="退货时间" min-width="150">
            <template slot-scope="{ row }">
              <span v-if="row.updateTime">{{ row.updateTime | parseTime }}</span>
              <span v-else>{{ row.createTime | parseTime }}</span>
            </template>
          </vxe-column>
          <vxe-column field="returnsState" title="状态" width="100">
            <template slot-scope="{ row }">
              <el-tag v-if="row.returnsState === '0'" type="info" size="small">未审核</el-tag>
              <el-tag v-if="row.returnsState === '1'" type="danger" size="small">审核拒绝</el-tag>
              <el-tag v-if="row.returnsState === '2'" size="small">审核通过</el-tag>
            </template>
          </vxe-column>

          <vxe-column fixed="right" title="操作" width="200"
            v-if="$showFn(['procurereturn_detail', 'procureexamine_examine'])">
            <template slot-scope="{row}">
              <el-button type="text" @click="toDetailOrExamine(row, true)" v-has="'procurereturn_detail'">详情</el-button>
              <el-button v-if="row.returnsState == '0'" type="text" @click="toDetailOrExamine(row, false)"
                v-has="'procureexamine_examine'">审核</el-button>
            </template>
          </vxe-column>
        </vxe-table>
      </div>

      <div class="paginationBox">
        <el-pagination background :current-page.sync="page.pageNum" :page-sizes="$pageSizes"
          :page-size.sync="page.pageSize" layout="total,-> , sizes, prev, pager, next, jumper" :total="page.total"
          @size-change="changePageSize" @current-change="getExamineList" />
      </div>

    </div>
  </div>
</template>

<script>
import { reqExamineList } from '@/api/procure'
import { getShopEasy } from '@/api/shop'
export default {
  name: 'ProcureReturn',
  data() {
    return {
      shopLists: [],
      page: {
        pageNum: 1,
        pageSize: 20,
        total: 0
      },
      form: {
        storeId: '',
        returnsNumber: '',
        returnsState: ''
      },
      tableData: [],
      isSearch: false,
    }
  },
  mounted() {
    // this.getShopEasy()
    this.getExamineList()
  },
  methods: {
    // 获取门店列表
    async getShopEasy() {
      const res = await getShopEasy()
      if (res.code === 200) {
        this.shopLists = res.data.store
        console.log(res)
      }
    },
    // 获取表格数据
    async getExamineList() {
      const { pageNum, pageSize } = this.page
      let { returnsNumber, storeId, returnsState } = this.form
      if (!this.isSearch) {
        returnsNumber = ''
        storeId = ''
        returnsState = undefined
      }
      const reqObj = { pageNum, pageSize, returnsNumber, returnsState, storeId }
      const res = await reqExamineList(reqObj)
      if (res.code === 200) {
        this.tableData = res.data.list
        this.page.total = res.data.total
        const $table = this.$refs.xTable1
        $table.loadData(this.tableData);
      }
    },
    // 修改每页几条
    changePageSize() {
      this.page.pageNum = 1
      this.getExamineList()
    },
    // 搜索
    searchList() {
      this.page.pageNum = 1
      this.isSearch = true
      this.getExamineList()
    },
    // 重置
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.page.pageNum = 1
      this.page.pageSize = 20
      this.isSearch = false
      this.getExamineList()
    },
    toDetailOrExamine(row, isDetail) {
      if (isDetail) {
        this.$router.push({ path: 'procureReturnDetail', query: { isDetail: 'detail', id: row.id } });
      } else {
        this.$router.push({ path: 'procureReturnExamine', query: { isDetail: 'SH', id: row.id } });
      }
    }
  }
}
</script>

<style lang="scss" scoped></style>
